#ifndef VIDEOCAPTURER_H
#define VIDEOCAPTURER_H

#include<functional>
#include"commonlooper.h"
#include"mediabase.h"
using std::function;



class VideoCapturer : public CommonLooper
{
public:
    VideoCapturer();
    virtual ~VideoCapturer();
    ///
    /// \brief init
    /// \param properties
    ///         x: x起始位置，缺省0
    ///         y: y起始位置，缺省0
    ///         width：宽度，缺省为屏幕宽度
    ///         height：高度，缺省为屏幕高度
    ///         format：像素格式，缺省为 YUV420P
    ///         fpg：帧数，缺省为 25
    /// \return
    ///
    RET_CODE init(const Properties& properties);
    virtual void loop();
    void addCallback(function<void(uint8_t*,int32_t)> callback);
private:
    int _video_test = 0;//视频测试模式
    std::string _input_yuv_name;
    int _x;
    int _y;
    int _width;
    int _height;
    int _pixel_format;
    int _fps;
    double _frame_duration;
    // 本地文件测试
    int openYuvFile(const char* file_name);
    int readYuvFile(uint8_t* yuv_buf, int32_t yuv_buf_size);
    int closeYuvFile();
    int64_t _yuv_start_time;//起始时间戳
    double _yuv_total_duration;//推流累计时间
    FILE *_yuv_fp = NULL;
    uint8_t* _yuv_buf = NULL;
    int _yuv_buf_size;

    function<void(uint8_t*, int32_t)> _callbak;
    bool _is_first_frame = false;//是否是第一次读到帧

};

#endif // VIDEOCAPTURER_H
